import 'package:flutter/material.dart';
import 'package:lib_common/components/widget/ntt_gesture_widget.dart';

import '../../r.dart';

/// 返回按钮
class NttBackButton extends StatelessWidget {
  /// 组件宽度
  final double width;
  final double height;

  /// 圆角
  final BorderRadius? radius;

  /// 填充颜色
  final Color? backgroundColor;

  /// 子组件宽度
  final double? childWidth;

  /// 子组件高度
  final double? childHeight;

  /// 图片显示方式
  final BoxFit? fit;

  /// 点击事件
  final Function()? onTap;

  /// 图片地址 建议使用绝对路径 否则可能会出现图片加载失败的情况
  /// packages/图片所在包名/xxx/xxx.png
  /// 如 'packages/lib_common/assets/images/ui_back_icon.png'
  final String? imageUrl;

  /// 是否启用点击效果 如果设置了背景颜色可能点击效果不生效
  final bool isEnabledClickEffect;

  const NttBackButton({
    super.key,
    required this.width,
    required this.height,
    this.radius,
    this.backgroundColor,
    this.childWidth,
    this.childHeight,
    this.fit,
    this.onTap,
    this.imageUrl,
    this.isEnabledClickEffect = false,
  });

  @override
  Widget build(BuildContext context) {
    return NttGestureWidget(
      isEnabledClickEffect: isEnabledClickEffect,
      onTap: onTap,
      child: Container(
        width: width,
        height: height,
        alignment: Alignment.center,
        decoration: backgroundColor != null
            ? BoxDecoration(
                borderRadius: radius,
                color: backgroundColor,
              )
            : null,
        child: Image.asset(
          imageUrl ?? R.ui_back_icon_png,
          fit: fit,
          width: childWidth,
          height: childHeight,
        ),
      ),
    );
  }
}
